home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / share / gufw / model / Log.py < prev    next >
Encoding:
Python Source  |  2009-10-25  |  3.2 KB  |  105 lines

  1. # Gufw 9.10.4 - http://gufw.tuxfamily.org
  2. # Copyright (C) 2009 Marcos Alvarez Costales
  3. #
  4. # Gufw is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 3 of the License, or
  7. # (at your option) any later version.
  8. # Gufw is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11. # GNU General Public License for more details.
  12. # You should have received a copy of the GNU General Public License
  13. # along with Gufw; if not, see http://www.gnu.org/licenses for more
  14. # information.
  15.  
  16.  
  17. import time
  18. import commands
  19. from Variable import Variable
  20.  
  21.  
  22. class Log:
  23.  
  24.     def __init__(self):
  25.     
  26.         self.variable = Variable()
  27.         
  28.         self.msgs     = []
  29.         self.wrapping = self.variable.get_constant("disabled")
  30.         self.status   = self.init_status_log()
  31.  
  32.  
  33.     # Return status Log (enabled/disabled) and Log recorded
  34.     def init_status_log(self):
  35.         # Get Log Old
  36.         if not self.variable.dev:
  37.             log_recorder = commands.getstatusoutput(self.variable.get_command("get_log_file"))
  38.         else:
  39.             log_recorder = commands.getstatusoutput(self.variable.get_command("get_log_file_dev"))
  40.         
  41.         # File exist
  42.         if log_recorder[0] == 0:
  43.         
  44.             log_split = log_recorder[1].split("\n")
  45.             
  46.             for log_line in log_split:
  47.                 if log_line != "":
  48.                     self.msgs.append(log_line)
  49.             
  50.         # Set initial status
  51.         if not self.variable.dev:
  52.             command = commands.getstatusoutput(self.variable.get_command("cfg_gufw_log"))
  53.         else:
  54.             command = commands.getstatusoutput(self.variable.get_command("cfg_gufw_log_dev"))
  55.             
  56.         if command[0] == 0:
  57.             return self.variable.get_constant("gufw_log_on")
  58.         else:
  59.             return self.variable.get_constant("gufw_log_off")
  60.  
  61.         
  62.     # Add Log
  63.     def add_log(self, status, msg_log):
  64.  
  65.         if status == self.variable.get_constant("gufw_log_off"):
  66.             return
  67.             
  68.         actual_time = "[" + time.strftime('%x %X') + "] "
  69.         msg  = actual_time + str(msg_log)
  70.  
  71.         # Append to Log List & Log File
  72.         self.msgs.append(msg)
  73.         
  74.         if not self.variable.dev:
  75.             commands.getstatusoutput(self.variable.get_command("append_log_file").replace("&",msg))
  76.         else:
  77.             commands.getstatusoutput(self.variable.get_command("append_log_file_dev").replace("&",msg))
  78.  
  79.         
  80.     # Return all log messages
  81.     def get_log(self):
  82.         return self.msgs
  83.         
  84.         
  85.     # Refresh Log
  86.     def refresh_log(self):
  87.         self.msgs = []
  88.         if not self.variable.dev:
  89.             commands.getstatusoutput(self.variable.get_command("refresh_log_file"))
  90.         else:
  91.             commands.getstatusoutput(self.variable.get_command("refresh_log_file_dev"))
  92.  
  93.  
  94.     # Set Wrapping
  95.     def set_wrapping(self, wrapping):
  96.         self.wrapping = wrapping
  97.         return wrapping
  98.  
  99.  
  100.     # Get Wrapping
  101.     def get_wrapping(self):
  102.         return self.wrapping
  103.